from django.db import models


# Create your models here.
class User(models.Model):
    username = models.CharField(max_length=20, unique=True)
    password = models.CharField(max_length=20)
    admin = models.BooleanField(default=False)
    worker = models.BooleanField(default=False)

class UserInfo(models.Model):
    SEX = [
        (0, "女"),
        (1, "男"),
    ]
    id = models.IntegerField(primary_key=True)
    avatar = models.ImageField(upload_to='photos', null=True)
    name = models.CharField(max_length=20, null=True)
    sex = models.IntegerField(choices=SEX, null=True)
    mobile = models.CharField(max_length=20, null=True)
    id_number = models.CharField(max_length=20, null=False)
    email = models.EmailField(max_length=50, unique=True, null=False)
    confirmed = models.BooleanField(default=False)
    register_time = models.DateTimeField(null=True, auto_now_add=True)

    def get_info(self):
        dic = dict()
        user = User.objects.get(id=self.id)
        dic['username'] = user.username
        dic['admin'] = user.admin
        dic['worker'] = user.worker
        dic['uid'] = self.id
        dic['realname'] = self.name
        dic['sex'] = self.sex
        dic['mobile'] = self.mobile
        dic['id_number'] = self.id_number
        dic['email'] = self.email
        return dic
    
class ConfirmCode(models.Model):
    code = models.CharField(max_length=255)
    uid = models.IntegerField(default=0)
    register_time = models.DateTimeField(auto_now_add=True)
